import { useDetail, useList } from "@/hooks";
import { getUserInfoUrl } from "@/command/apiTool";
import { getAction, postAction } from "@/command/netTool";
import * as vant from "vant";
const { showFailToast, showSuccessToast } = vant;
import { useRouter } from "vue-router";
import { back } from "@/command/router";
export const useRequest = () => {
  const router = useRouter();
  const [entityList] = useDetail("/api/H5/util/getEntityType", []);

  const [personCenterMainBody] = useDetail(
    getUserInfoUrl({
      dh: "/api/H5/gov/perCenter/personCenterMainBody",
      xh: "/api/H5/gov/perCenter/personCenterMainBody",
    }),
    {
      areaCode: "",
      areaName: "",
      countryCode: "",
      countryName: "",
      entityComment: "",
      entityName: "",
      id: "",
      mccid: "",
      phone: "",
      productTypeId: "",
      logo: "",
    }
  );

  const [getProductRoot] = useDetail("/api/H5/util/getProductLevel", [], {
    callBack: (data: any[]) => {
      return data.filter((e) => e.value != "-1");
    },
  });
  const [countryList] = useDetail(
    "/api/H5/util/getDictType?dictType=country_code",
    [],
    {
      callBack: (data: any[]) => {
        return data.filter((e) => e.value != "-1");
      },
    }
  );
  // const [getProductRoot] = useDetail(
  //   getUserInfoUrl({
  //     dh: "/api/H5/util/getProductRoot",
  //     xh: "/api/H5/util/getProductRoot",
  //   }),
  //   [
  //     {
  //       name: "",
  //       id: "",
  //     },
  //   ]
  // );
  const confirm = (params: any) => {
    postAction(
      "api/H5/gov/perCenter/savePersonCenterMainBody",
      { ...params },
      { isResolve: true }
    ).then((e) => {
      showSuccessToast(e.msg);
      back();
    });
  };
  return {
    confirm,
    personCenterMainBody,
    getProductRoot,
    entityList,
    countryList,
  };
};
